﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using TestPlatform.Core;

namespace TestPlatform.Performer.Mssql
{
    public class MssqlGetByIdPerformer : BaseGetByIdPerformer
    {
        public override string UnderlyinEngine { get { return "MSSQL"; } }

        public MssqlGetByIdPerformer()
            : base(new MssqlHelper())
        {

        }

        protected override void EntityGetById(Guid id)
        {
            using (var c = MssqlHelper.CreateConnection())
            {
                SqlCommand cmd = c.CreateCommand();
                cmd.CommandText = string.Format("SELECT [Id], [Login], [Name] FROM [Users] WHERE Id = '{0}'", id);

                using (SqlDataReader r = cmd.ExecuteReader())
                {
                    r.Read();

                    Guid readId = (Guid)r["Id"];
                    string readLogin = (string)r["Login"];
                    string readName = (string)r["Name"];

                    Defer(readId, readLogin, readName);
                }
            }
        }
    }
}
